﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using Microsoft.Phone.Data.Linq;
using Microsoft.Phone.Data.Linq.Mapping;
using System.ComponentModel;

namespace Type2Diabetes
{
    public class DBContext : DataContext
    {
        public static string DBConnectionString = "isostore:/feeds.sdf";
        public DBContext(string constring) : base(constring) { }
        public Table<Person> person;
        public Table<Doctor> doctor;
        public Table<Devices> devices;
        public Table<GlucoseHist> GlucoseHist;
        public Table<GlucoseGoal> GlucoseGoal;
        public Table<Food> food;
        public Table<FoodHist> foodhistory;
    }
    [Table]
    public class Person
    {
        public Person() { }
        public Person(int PersonID, string FName,
                      string LName, string Gender,
                      DateTime DateOfBirth, float Height,
                      float Weight, float IdealWeight,
                      DateTime DiagnosisDate, float DiabType)
        {
            PID = PersonID;
            fname = FName;
            lname = LName;
            gen = Gender;
            dob = DateOfBirth;
            ht = Height;
            wt = Weight;
            idealwt = IdealWeight;
            diadate = DiagnosisDate;
            diabtype = DiabType;
        }
        int _PID;
        string _fname;
        string _lname;
        string _gen;
        DateTime _dob;
        float _ht;
        float _wt;
        float _idealwt;
        DateTime _diadate;
        float _diabtype;
        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]

        public int PID
        {
            get { return _PID; }
            set { _PID = value; }
        }
        [Column]
        public string fname
        {
            get { return _fname; }
            set { _fname = value; }
        }
        [Column]
        public string lname
        {
            get { return _lname; }
            set { _lname = value; }
        }
        [Column]
        public string gen
        {
            get { return _gen; }
            set { _gen = value; }
        }
        [Column]
        public DateTime dob
        {
            get { return _dob; }
            set { _dob = value; }
        }
        [Column]
        public float ht
        {
            get { return _ht; }
            set { _ht = value; }
        }
        [Column]
        public float wt
        {
            get { return _wt; }
            set { _wt = value; }
        }
        [Column]
        public float idealwt
        {
            get { return _idealwt; }
            set { _idealwt = value; }
        }
        [Column]
        public DateTime diadate
        {
            get { return _diadate; }
            set { _diadate = value; }
        }
        [Column]
        public float diabtype
        {
            get { return _diabtype; }
            set { _diabtype = value; }
        }

    }

    [Table]
    public class Doctor
    {

        public Doctor() { }
        public Doctor(int DoctorID, string FName,
                      string LName, string OfficeName,
                      string Email, int Phone, string Role)
        {
            docid = DoctorID;
            docfname = FName;
            doclname = LName;
            docoffname = OfficeName;
            docemail = Email;
            docph = Phone;
            docrole = Role;
        }

        int _docid;
        string _docfname;
        string _doclname;
        string _docoffname;
        string _docemail;
        int _docph;
        string _docrole;

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int docid
        {
            get { return _docid; }
            set { _docid = value; }
        }
        [Column]
        public string docfname
        {
            get { return _docfname; }
            set { _docfname = value; }
        }
        [Column]
        public string doclname
        {
            get { return _doclname; }
            set { _doclname = value; }
        }
        [Column]
        public string docoffname
        {
            get { return _docoffname; }
            set { _docoffname = value; }
        }
        [Column]
        public string docemail
        {
            get { return _docemail; }
            set { _docemail = value; }
        }
        [Column]
        public int docph
        {
            get { return _docph; }
            set { _docph = value; }
        }
        [Column]
        public string docrole
        {
            get { return _docrole; }
            set { _docrole = value; }
        }
    }

    [Table]
    public class Devices
    {

        public Devices() { }
        public Devices(int DeviceID, string Name, string Manufacturer)
        {
            devid = DeviceID;
            devname = Name;
            manu = Manufacturer;
        }

        int _devid;
        string _devname;
        string _manu;

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]

        public int devid
        {
            get { return _devid; }
            set { _devid = value; }
        }
        [Column]
        public string devname
        {
            get { return _devname; }
            set { _devname = value; }
        }
        [Column]
        public string manu
        {
            get { return _manu; }
            set { _manu = value; }
        }
    }

    [Table]
    public class GlucoseHist
    {
        public GlucoseHist() { }
        public GlucoseHist(string GHID, 
            int PersonID, int DeviceID, 
            float GlucoseValue, DateTime DateTime, 
            string GHNotes, string WhereMeasured)
        {
            GlucoseHistID = GHID;
            DID = DeviceID;
            GValue = GlucoseValue;
            DT = DateTime;
            GlucoseHistNotes = GHNotes;
            WM = WhereMeasured;
        }
        string _GlucoseHistID;
        float _GValue;
        DateTime _DT;
        string _GlucoseHistNotes;
        string _WM;
        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public string GlucoseHistID
        {
            get { return _GlucoseHistID; }
            set { _GlucoseHistID = value; }
        }
        [Column]
        public int PID;
        private EntityRef<Person> _PID;
        [Association(Storage = "_PID", ThisKey = "PID", IsForeignKey = true)]
        public Person personID
        {
            get { return this._PID.Entity; }
            set { this._PID.Entity = value; }
        }
        [Column]
        public int DID;
        private EntityRef<Devices> _devid;
        [Association(Storage = "_devid", ThisKey = "DID", IsForeignKey = true)]
        public Devices devid
        {
            get { return this._devid.Entity; }
            set { this._devid.Entity = value; }
        }
        [Column]
        public float GValue
        {
            get { return _GValue; }
            set { _GValue = value; }
        }
        [Column]
        public DateTime DT
        {
            get { return _DT; }
            set { _DT = value; }
        }
        [Column]
        public string GlucoseHistNotes
        {
            get { return _GlucoseHistNotes; }
            set { _GlucoseHistNotes = value; }
        }
        [Column]
        public string WM
        {
            get { return _WM; }
            set { _WM = value; }
        }
    }

    [Table]
    public class GlucoseGoal
    {
        public GlucoseGoal() { }
        public GlucoseGoal(int GluGoalID, int PersonID, float GLowValue, float GHighValue, float GluGValue)
        {
            GGID = GluGoalID;
            PID = PersonID;
            GLV = GLowValue;
            GHV = GHighValue;
            GGV = GluGValue;
        }
        int _GGID;
        float _GLV;
        float _GHV;
        float _GGV;
        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int GGID
        {
            get { return _GGID; }
            set { _GGID = value; }
        }
        [Column]
        public int PID;
        private EntityRef<Person> _PID;
        [Association(Storage = "_PID", ThisKey = "PID", IsForeignKey = true)]
        public Person personID
        {
            get { return this._PID.Entity; }
            set { this._PID.Entity = value; }
        }
        [Column]
        public float GLV
        {
            get { return _GLV; }
            set { _GLV = value; }
        }
        [Column]
        public float GHV
        {
            get { return _GHV; }
            set { _GHV = value; }
        }
        [Column]
        public float GGV
        {
            get { return _GGV; }
            set { _GGV = value; }
        }

    }

    [Table]
    public class Food
    {
        public Food() { }
        public Food(int FoodID, string FoodName,
                    float ServSize, string ServSizeUnits,
                    float CalPerServ, float CarbsPerServ,
                    float ProteinPerServ, float FatPerServ)
        {
            fid = FoodID;
            foodname = FoodName;
            ss = ServSize;
            ssu = ServSizeUnits;
            calps = CalPerServ;
            carps = CarbsPerServ;
            pps = ProteinPerServ;
            fps = FatPerServ;
        }
        int _fid;
        string _foodname;
        float _ss;
        string _ssu;
        float _calps;
        float _carps;
        float _pps;
        float _fps;
        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int fid
        {
            get { return _fid; }
            set { _fid = value; }
        }
        [Column]
        public string foodname
        {
            get { return _foodname; }
            set { _foodname = value; }
        }
        [Column]
        public float ss
        {
            get { return _ss; }
            set { _ss = value; }
        }
        [Column]
        public string ssu
        {
            get { return _ssu; }
            set { _ssu = value; }
        }
        [Column]
        public float calps
        {
            get { return _calps; }
            set { _calps = value; }
        }
        [Column]
        public float carps
        {
            get { return _carps; }
            set { _carps = value; }
        }
        [Column]
        public float pps
        {
            get { return _pps; }
            set { _pps = value; }
        }
        [Column]
        public float fps
        {
            get { return _fps; }
            set { _fps = value; }
        }

    }
    
    [Table]
    public class FoodHist
    {

        public FoodHist() { }
        public FoodHist(int FHID, int FoodID,
                        DateTime DateTime, float Quantity,
                        string FHNotes, int PersonID)
        {
            fhid = FHID;
            datetime = DateTime;
            qty = Quantity;
            fhnotes = FHNotes;
        }
        int _fhid;
        DateTime _datetime;
        float _qty;
        string _fhnotes;

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int fhid
        {
            get { return _fhid; }
            set { _fhid = value; }
        }

        [Column]
        public int foodid;
        private EntityRef<Food> _fid;
        [Association(Storage = "_fid", ThisKey = "foodid", IsForeignKey = true)]
        public Food food
        {
            get { return this._fid.Entity; }
            set { this._fid.Entity = value; }
        }

        [Column]
        public DateTime datetime
        {
            get { return _datetime; }
            set { _datetime = value; }
        }
        [Column]
        public float qty
        {
            get { return _qty; }
            set { _qty = value; }
        }
        [Column]
        public string fhnotes
        {
            get { return _fhnotes; }
            set { _fhnotes = value; }
        }
        [Column]
        public int pid;
        private EntityRef<Person> _pid;
        [Association(Storage = "_pid", ThisKey = "pid", IsForeignKey = true)]
        public Person person
        {
            get { return this._pid.Entity; }
            set { this._pid.Entity = value; }
        }
    }

}
